Skip to content

Contract clauses: REQUIRE, ENSURE, NEVER (90-day plan, build 3) - #26

Open
alakanani wants to merge 1 commit into
mainfrom
intent-contracts-2026-11
Open

alakanani wants to merge 1 commit into
mainfrom
intent-contracts-2026-11

Conversation

@alakanani

Copy link
Copy Markdown
Collaborator

Build 3 of the 90-day plan: the checkable half of a rite's promise, beside DECLARE INTENT's prose. The founder gave the green light for the three keywords on 2026-11-17.

What lands

  • Clauses are declarations. REQUIRE / ENSURE / NEVER written as lines of a rite body are lifted out by the parser into the rite's contract, in written order. They never execute as steps, and one written after a RETURN binds exactly as one written before it. A clause outside a rite body, or nested in a branch, is a gentle parse error.
  • Weighed at the thresholds. REQUIRE at entry, in the invocation frame with parameters bound, before the body runs (failure means the body does not run). ENSURE at exit, in the rite's frame with the body's names still in scope, after RETURN as after a plain ending. NEVER at both doors, and in this first form only at the doors, never continuously while the body runs; the spec (SX-44) and the reference say so plainly.
  • Failure is real. A broken clause raises ContractError (machine code CONTRACT_ERROR), naming the rite, the clause as written, and the values it was weighed against. The invocation's intent record is marked aligned: false. TRY/CATCH at a call site may shelter it, as any runtime failure.
  • The report grows additively. Run reports (run --json, run --sandbox --json, the playground payload, the bridge run tool) gain a contracts array: {rite, kind, text, passed}, one entry per weighing. The dated run schema gains the field additively; required fields are untouched. Sandbox behaviour is identical.
  • Examples. examples/intent_demo.god gains a baking rite whose clauses all hold; the math scroll's FACTORIAL now swears REQUIRE n >= 0.
  • Docs. LANGUAGE_REFERENCE section 9; spec rules SX-40 to SX-45 (syntax layer) and the three words join the keyword inventory at LX-7; machine-interfaces; AGENTS.md; CHANGELOG. LSP hover docs for the three words. Playground bundle rebuilt per house rules.

Proof (real engine)

  • bake(0) with REQUIRE loaves > 0: ok:false, exit 1, CONTRACT_ERROR, output empty (the body never revealed), contracts array holds the failed REQUIRE.
  • bake(5): passes; contracts array shows REQUIRE, NEVER (entry), ENSURE, NEVER (exit), all passed.
  • ENSURE failure (bake(3) against ENSURE loaves IS 5) and NEVER failure (lend(5) against NEVER debt > 0) each fail the run with the covenant message and the values named.

Tests

1093 passed (baseline 1066, plus 27 new in tests/test_intent_contracts.py). Examples parity checked against main: the same five grant-needing examples fail a bare sandbox run on both.

Notes for review

  • Likely merge overlap with PR Loud errors: a name bound nowhere is never read silently #25 (loud-errors-2026-11): both touch godcode/interpreter.py around _call_rite and statement dispatch, plus AGENTS.md, CHANGELOG.md, and the playground bundle. This branch builds independently from main; the overlap is flagged, not resolved.
  • Awaiting the founder's vetting: tongue equivalents for REQUIRE / ENSURE / NEVER. The clause words are English in every tongue for now.
  • Follow-up: llms.txt (in PR Publish llms.txt: God Code, readable by AI systems #23) needs a contracts paragraph once both PRs land.

The checkable half of a rite's promise, beside DECLARE INTENT's prose.
Clauses are declarations in a rite body, gathered by the parser into
the rite's contract in written order; they never execute as steps.
REQUIRE is weighed at entry (parameters bound, body not yet run),
ENSURE at exit (the rite's frame, after RETURN too), NEVER at both
thresholds. A broken clause fails the run with ContractError
(CONTRACT_ERROR), naming the rite, the clause, and the values weighed;
the run report gains an additive contracts array. A contract-failed
invocation's intent record is marked unaligned. Sandbox behaviour is
identical; clause words are English in every tongue for now.

Spec: SX-40 to SX-45 in the syntax layer, the three words join LX-7.
Docs: LANGUAGE_REFERENCE section 9, machine-interfaces, AGENTS.md,
CHANGELOG. Examples: intent_demo gains a baking rite whose clauses
hold; the math scroll's FACTORIAL swears REQUIRE n >= 0. Playground
bundle rebuilt. 27 new tests in tests/test_intent_contracts.py.
@vercel

vercel Bot commented Nov 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
godcode Ready Ready Preview Nov 17, 2026 7:04pm UTC

This branch was successfully deployed

1 active deployment
Preview — 48b4f3e2 Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants